<template>
  <div class="search-content"  :style="{top: GLOBAL.currentEnvironment ? '0' : '0.35rem'}">
    <!-- <Navbar :appTitle="title"  :rname="rname" /> -->
    <Search ref="topSearch" class="search" placeholder="商品名称|商品编号|订单编号" :isAdd="false" :isScreen="false" :isType="false"></Search>

    <div class="formgroup">
      <span class="title">生产负责人</span>
      <van-field
        is-link
        readonly
        name="picker"
        @click="chooseUser"
        v-model="fzrName"
        placeholder="请选择"
      >
      <div slot="right-icon" v-show="!!fzrName" @click.stop="cancelFzrName"><van-icon name="clear" size="0.16rem" /></div>
      </van-field>
      <span class="title">工艺路线</span>
      <van-field
        name="picker"
        v-model="params.craftName"
        placeholder="请输入"
      >
      </van-field>
    </div>
    <div class="formgroup">
      <span class="title">承诺交期</span>
      <dateTime
                title="订单提交"
                type="date"
                :startTime="params.promiseDateBegin"
                :endTime="params.promiseDateEnd"
                @confirmTime="confirmCnTime"
                :supportClear="true"
              />
      
      <span class="title">订单提交时间</span>
        <dateTime
                title="订单提交"
                type="date"
                :startTime="params.createdTimeBegin"
                :endTime="params.createdTimeEnd"
                @confirmTime="confirmDdTime"
                :supportClear="true"
              />
      <span class="title">订单提交人</span>
      <van-field
        :is-link="!createdByName"
        readonly
        name="picker"
        v-model="createdByName"
        @click="ddthrVisible = true"
        placeholder="请选择"
      >
      <div slot="right-icon" v-show="!!createdByName" @click.stop="cancelCreatedBy"><van-icon name="clear" size="0.16rem" /></div>

      </van-field>
      <span class="title">销售合同编号</span>
      <van-field v-model="params.contractCode" placeholder="请输入" />
       
     
    </div>
     <!-- <upload  iconType="fj" @fileChange="fileChange"
     :fileIds="fileIds"
     ></upload> -->
    <div class="search-bottom">
      <span class="btncancel" @click="cancel">重置</span>
      <span class="btnconfirm" @click="confirm">确定</span>
    </div>
   

    
    <contact-pickers :visible="fzrVisible" @confirm="confirmChooseUsers">
    </contact-pickers>
    <contact-pickers :visible="ddthrVisible" @confirm="confirmDdtjr">
    </contact-pickers>
  </div>
</template>

<script>
const formP={
        status: 0,
        chargeUserId: "", //生产负责人ID
        craftName: "",
        contractCode: "",
        createdBy: "",
        promiseDateBegin: "",
        promiseDateEnd: "",
        createdTimeBegin:"",
        createdTimeEnd:"",
}
import Navbar from "@/components/navBar/navBar_right";
import ContactPickers from "@/components/choiceuse/ContactPickers";
import upload from "@/components/upload/upload";
import moment from "moment";
import DateTime from "@/components/form/dateTimeSection";
import Search from "@/components/search";
export default {
  name: "search",
  components: { Navbar, ContactPickers,upload,DateTime,Search},
  data() {
    return {
      timeDdtjStr:"",
      title: "更多筛选1",
      fzrVisible: false,
      ddthrVisible: false,
      promiseDateStartVisible: false,
      promiseDateEndVisible: false,
      promiseDateStr:"",
      createdTimeBeginVisible:false,
      createdTimeEndVisible:false,
      fzrName: "", //生产负责人
      createdByName: "", //订单提交人
      // rtitle: "更多筛选",
      rname: "", //search
      fileIds:"1509889200026275842,1510083205250818050,1509894546648190978",
      minDate: new Date(2020, 1, 1),
      maxDate: new Date(2025, 10, 1),
      params:  Object.assign({}, formP),
    };
  },
  props: {
    keyword: {
      type: String,
      default: "",
    },
  },
   watch: {
    keyword(newVal) {
      this.$refs.topSearch.value = newVal;
    },
  },
  computed: {},
  mounted() {},
  created() {
   
  
  },
  methods: {
    cancelFzrName(){
      this.params.chargeUserId = "";
      this.fzrName = "";
    },
    cancelCreatedBy(){
      this.params.createdBy = "";
      this.createdByName = "";
    },
  
    confirmDdTime(startTime,endTime){
        // 改变父组件的值
        console.log("startTime"+startTime)
        console.log("endTime"+endTime)
        this.params.createdTimeBegin=startTime
        this.params.createdTimeEnd=endTime
        
    },
    confirmCnTime(startTime,endTime){
        // 改变父组件的值
        console.log("startTime"+startTime)
        console.log("endTime"+endTime)
        this.params.promiseDateBegin=startTime
        this.params.promiseDateEnd=endTime 
    },
    fileChange(ids){
      console.log("父组件"+ids)
    },
 
    formatter(type, val) {
      if (type === "year") {
        return val + "年";
      }
      if (type === "month") {
        return val + "月";
      }
      if (type === "day") {
        return val + "日";
      }
      if (type === "hour") {
        return val + "时";
      }
      if (type === "minute") {
        return val + "分";
      }
      return val;
    },
    chooseUser() {
      this.fzrVisible = true;
    },
    confirmChooseUsers(val, selectedList, judge) {
      this.params.chargeUserId = "";
      this.fzrName = "";
      if (judge) {
        this.fzrVisible = false;
        return;
      }
      this.params.chargeUserId = val ? val : ""; //人员id
      let arr = [];
      if (selectedList) {
        selectedList.forEach((item) => {
          arr.push(item.realname);
        });
      }
      this.fzrName = arr.join(",");
      this.fzrVisible = false;
    },
    confirmDdtjr(val, selectedList, judge) {
      this.params.createdBy = "";
      this.createdByName = "";
      if (judge) {
        this.ddthrVisible = false;
        return;
      }
      this.params.createdBy = val ? val : ""; //人员id
      let arr = [];
      if (selectedList) {
        selectedList.forEach((item) => {
          arr.push(item.realname);
        });
      }
      this.createdByName = arr.join(",");
      this.ddthrVisible = false;
    },
    cancel() {
      this.timeDdtjStr=""
      this.fzrName=""
      this.createdByName=""
      this.$refs.topSearch.value = "";
      this.params = Object.assign({}, formP)
      // this.$emit('resetCategory')

    // this.$router.push({ path: '/approval', query: {approveType:1,taskId:"4555"} })

    },
    confirm() {
      // this.$router.push({ path: "/carRoomList" });
      var keyword = this.$refs.topSearch.value
      console.log("++++++++++++++++")
      console.log(this.params)
      this.$emit('getCategory', this.params,keyword)
    },
  },
};
</script>
<style lang="scss" scoped>
.search-content {
  //  padding-bottom: 0.5rem;
    position: fixed;
    top: 0.35rem;
    width: 100%;
    height: 100vh;
    background-color: #f5f5f5;
    // padding-top: 0.1rem;
    z-index: 99;
    .pph{
      height: 100vh;
    }
  .formgroup {
    background-color: #ffffff;
    // padding: 0 0.16rem;
    margin-top: 0.1rem;
    // margin-bottom: 0.2rem;
    padding-top: 0.1rem;
    
    .title {
      width: 0.58rem;
      height: 0.14rem;
      font-size: 0.15rem;
      font-family: PingFang SC;
      font-weight: 400;
      color: #191f25;
      line-height: 0.05rem;
      margin-left: 0.16rem;
      // background-color: red;
    }
  }
  .search-bottom {
    height: 0.5rem;
    width: 100%;
    background: #ffffff;
    // background: red;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: fixed;
    bottom: 0px;
    padding: 0.11rem;
    .btnconfirm {
      width: 1.72rem;
      height: 0.39rem;
      background: #1890ff;
      border-radius: 0rem;
      text-align: center;
      line-height: 0.39rem;
      color: #fff;
    }
    .btncancel {
      width: 1.72rem;
      height: 0.39rem;
      background: #f6f6f6;
      // border: 0.01px solid rgba(25, 31, 37, 0.12);
      border-radius: 0rem;
      text-align: center;
      line-height: 0.39rem;
    }
  }
}
</style>